package com.lanou.horo.zhuizhui.adapter;

import java.util.List;


import com.lanou.horo.zhuizhui.entity.RecentComicsItem;
import com.lanou.horo.zhuizhui.fragment.DialogFragmentPage;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.Log;

public class DialogViewPagerAdapter extends FragmentPagerAdapter {
    private List<RecentComicsItem.ComicsEntity> entities;
    private RecentComicsItem.ThemeEntity themeEntity;

    public DialogViewPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    public void addTh(RecentComicsItem.ThemeEntity data){
        themeEntity = data ;
        notifyDataSetChanged();
    }
    public void addData(List<RecentComicsItem.ComicsEntity> datas) {
        entities = datas;
        notifyDataSetChanged();
    }

    @Override
    public Fragment getItem(int postion) {
        RecentComicsItem.ComicsEntity rc = entities.get(postion);
        String dialogName = rc.getName();
        String dialogAuthor = rc.getAuthor();
        String dialogCategoryName = rc.getCategory_name();
        String dialogUpdate = String.valueOf(rc.getLast_volume_updated_at());
        String dialogLastVolume = rc.getLast_volume();
        String dialogImage = rc.getCover_img();
        String dialogRanking = "";
        if (themeEntity != null) {
            if (themeEntity.getName().equals("排行榜")) {
                dialogRanking = (postion + 1) + "";
            }
        }
        return DialogFragmentPage.getInstance(dialogName, dialogImage, dialogAuthor,
                dialogCategoryName, dialogUpdate, dialogLastVolume,dialogRanking);
    }

    @Override
    public int getCount() {

        return entities != null && entities.size() > 0 ? entities.size() : 0;
    }
}
